#ifndef _SPK_PACKET_H_
#define _SPK_PACKET_H_

#include "config.h"

#define SPK_PACKET_HEADER		0x55
#define SPK_PACKET_MIN_TYPE		1
#define SPK_PACKET_MAX_TYPE		255
#define SPK_PACKET_MAX_LEN		4096

/*每当接收到一个标准的数据包时调用*/
/*用户应该在此回调函数中仅完成PostMessage等实现与UI线程的交互*/
typedef void(*__spk_packet_callback_func)(void* rx_buffer, int len, u8 type, void* param);
typedef int (*__spk_packet_io_read_func)(void* data, int len, int time_out_ms, void* param);

typedef __spk_packet_callback_func spk_packet_callback;
typedef __spk_packet_io_read_func  spk_packet_io_read_func;

class spk_packet
{
public:
	int send_packet(u8  type, void *data = NULL, u16 len = 0, void* param = NULL);
	static void recv_packet_thread(spk_packet_io_read_func io_read, spk_packet_callback on_rx_packet,void *param);
	static void recv_packet_thread_ex(spk_packet_io_read_func io_read, spk_packet_callback on_rx_packet, void* param);

protected:
	virtual int io_write(void* data, int len, void* param = NULL) = 0;
};

#endif //  _SPK_PACKET_H_